package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.ArrayList;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.NetViewBinding;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/12 20:08
 * description:
 */
public class ServiceDetailAdapter extends RecyclerView.Adapter<ServiceDetailAdapter.ServiceDetailHolder> {
    private Context mContext;
    private ArrayList<String> title = new ArrayList<>();
    private ArrayList<String> itemData;

    public ServiceDetailAdapter(Context context) {
        mContext = context;
        title.add("A卡领卡换卡");
        title.add("A卡挂失补办");
        title.add("省一卡通");
        title.add("售卡");
        title.add("换卡");
        title.add("退卡");
        title.add("云闪充补登");
        title.add("电子钱包充值");
        title.add("利金卡售卡");
        title.add("充值卡售卡");
        title.add("充值卡充值");
        title.add("企服卡圈存");
        title.add("园林/休闲售后");
        title.add("园林续费");
        title.add("休闲办理");
        title.add("教育E卡通补换卡");
        title.add("亲子娃娃卡");
        title.add("月票.高龄卡");
        title.add("残疾人爱心卡");
        title.add("献血爱心卡");
        title.add("优待卡");
        title.add("饭堂卡");
        title.add("转转卡");
        title.add("公务卡");
        title.add("缴纳公共事业费");
        title.add("劳模卡");
        title.add("公共自行车卡");
        title.add("燃气补登");
        title.add("蛋糕卡");
        title.add("拥军卡");
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.net_view;

    }

    @Override
    public ServiceDetailHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return ServiceDetailHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(ServiceDetailHolder holder, int position) {
        loadItemData(position, holder.binding);

    }

    private void loadItemData(int position, NetViewBinding binding) {
        binding.box1.setText(title.get(position));
        String mTitle = title.get(position);
        if (itemData != null) {
            for (int i = 0; i < itemData.size(); i++) {
                String s = itemData.get(i);
                if (s != null) {
                    if (s.contains(mTitle)) {
                        binding.box1.setChecked(true);
                    }
                }
            }

        }
    }

    @Override
    public int getItemCount() {
        return null == title ? 0 : title.size();
    }

    public void setItemData(ArrayList<String> itemData) {
        this.itemData = itemData;
    }

    public static class ServiceDetailHolder extends RecyclerView.ViewHolder {

        private NetViewBinding binding;

        public static ServiceDetailHolder creat(ViewGroup parent) {
            NetViewBinding binding = NetViewBinding
                    .inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new ServiceDetailHolder(binding);
        }

        public ServiceDetailHolder(NetViewBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
